package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.InvoiceTotalInfoView;

public interface InvoiceTotalInfoViewRepository extends JpaRepository<InvoiceTotalInfoView, String> {

	@Query("select i from InvoiceTotalInfoView i where i.nBeLeftOverPrice > 0 and (i.sInvoiceName like '%'+?1+'%' or i.sInvoiceCustomerName like '%'+?1+'%' or i.sInvoiceTradeType like '%'+?1+'%' " + 
			" or i.sInvoiceCustomerAccount like '%'+?1+'%' or i.sInvoiceIdentifyType like '%'+?1+'%' or i.sInvoiceAccount like '%'+?1+'%') ")//i. like '%'+?1+'%'
	Page<InvoiceTotalInfoView> findAllBykey(String key, Pageable pageable);

	@Query("select count(*) from InvoiceTotalInfoView i where i.nBeLeftOverPrice > 0 and (i.sInvoiceName like '%'+?1+'%' or i.sInvoiceCustomerName like '%'+?1+'%' or i.sInvoiceTradeType like '%'+?1+'%' " + 
			" or i.sInvoiceCustomerAccount like '%'+?1+'%' or i.sInvoiceIdentifyType like '%'+?1+'%' or i.sInvoiceAccount like '%'+?1+'%') ")//i. like '%'+?1+'%'
	long findAllBykeyCount(String key);

	@Query("select i from InvoiceTotalInfoView i where (i.sInvoiceName like '%'+?1+'%' or i.sInvoiceCustomerName like '%'+?1+'%' or i.sInvoiceTradeType like '%'+?1+'%' " + 
			" or i.sInvoiceCustomerAccount like '%'+?1+'%' or i.sInvoiceIdentifyType like '%'+?1+'%' or i.sInvoiceAccount like '%'+?1+'%') ")//i. like '%'+?1+'%'
	Page<InvoiceTotalInfoView> findAllBykey1(String key, Pageable pageable);

	@Query("select count(*) from InvoiceTotalInfoView i where (i.sInvoiceName like '%'+?1+'%' or i.sInvoiceCustomerName like '%'+?1+'%' or i.sInvoiceTradeType like '%'+?1+'%' " + 
			" or i.sInvoiceCustomerAccount like '%'+?1+'%' or i.sInvoiceIdentifyType like '%'+?1+'%' or i.sInvoiceAccount like '%'+?1+'%') ")//i. like '%'+?1+'%'
	long findAllBykeyCount1(String key);

}
